<template>
  <div>
    <router-view v-slot="{ Component }">
      <transition name="fade">
        <component :is="Component" />
      </transition>
    </router-view>
  </div>

</template>


<script setup lang="ts">

import { getAutoLogin } from "@/server/login/index"
import { onMounted } from "vue";
import { useTabStore } from "@/store/useTabStore";
import {useRouter} from 'vue-router'

const router=useRouter()
const useTab = useTabStore()
//自动登录
onMounted(() => {


// router.push({name:"Home"})

  // if(!useTab.loginStatus) return
  //获取本地token
  const token = localStorage.getItem('token')
  //判断是否有token
  if (token) {
    const data = {
      token
    }
    getAutoLogin(data).then(res => {
      
      if (res.code == 200) {
        //更新用户名
        useTab.setUserName(res.data.username)
        //修改登录状态
        useTab.setLoginStatus(true)

        //更新用户头像
        useTab.setAvatar(res.data.avatar)

        //更新用户id
        useTab.setUserId(res.data.id)
      }else{
        //清除token
        console.log('1');
        
        localStorage.removeItem('token')
      }

    }).catch(err => {
      console.log(err)
    })
  }

})



</script>

<style lang="scss">
::v-deep .el-card.is-always-shadow {
  box-shadow: none;
}
</style>
